# Copyright (C) 2009-2012, LiTuX, All wrongs reserved.

# Version Control System Information: Subversion, host on <+ Google Code +>;
# $URL: http://sdusthesis.googlecode.com/svn/trunk/Makefile $;
# $Id: Makefile 18 2012-04-24 14:33:33Z suxpert@gmail.com $;

# Makefile for GNUmake, LaTeX -> pdf.

######## TeX tools: ########
TEX = xelatex # -quiet -interaction=nonstopmode
IDX = makeindex
BTX = bibtex

######## System tools: ########
OPEN = evince
RM = rm
MV = mv
CP = cp
TAR = tar -cjf

# OPEN = start
# RM = erase
# MV = rename
# CP = copy
# TAR = 7zip

# VPATH = sample

MAIN = stSamp
TITLE = SDUSThesis

TARGET = $(MAIN).pdf
BALL = $(TITLE).tar.bz2

SRC =	$(MAIN).tex\
	sample/stAbs.tex\
	sample/stDAbs.tex\
	sample/stBody.tex\
	sample/bibtex.tex\
	sample/standard.tex\
	sample/works.tex\
	sample/samp.tex\

DEPS =	SDUSThesis.cls\
	stSpec.sty\
	stLayout.sty\
	sdust.bbx\
	chinese.lbx\
	$(BIB)

BIB = sample/refs.bib
BBL = $(MAIN).bbl

ATTSRC = example_title.tex
ATTF = $(ATTSRC:.tex=)
ATT = $(ATTF).pdf
ATTTMP = $(ATTF).aux $(ATTF).out $(ATTF).log $(ATTF).run.xml $(ATTF)-blx.bib

EXTRA =	Makefile\
	README.md\
	sample/fig.png\
	$(ATTSRC)

# Various of temp files:
LOGS = $(MAIN).log
TOCS = $(MAIN).toc $(MAIN).toe
OUTS = $(MAIN).out
BLXS = $(MAIN).bbl $(MAIN)-blx.bib $(MAIN).run.xml $(MAIN).blg
IDXS = $(MAIN).idx $(MAIN).ind $(MAIN).ilg
NAVS = $(MAIN).nav $(MAIN).snm
AUXS = $(SRC:.tex=.aux)
BAKS = $(SRC:.tex=.tex~)
# Vim set backup; For Gedit or sth else, modify this to .bak or whatever.

$(TARGET): $(SRC) $(DEPS) $(ATT) $(BBL)
	$(TEX) $(MAIN)
	$(TEX) $(MAIN)

#	$(BTX) $(MAIN)
#	$(IDX) $(MAIN)
#	$(TEX) $(MAIN)

$(ATT): $(ATTSRC) $(DEPS)
	$(TEX) $(ATTSRC)

$(BBL): $(BIB) | $(MAIN).aux
	$(BTX) $(MAIN)

%.aux: %.tex
	$(TEX) $(MAIN)

.PHONY: clean distclean dist exec clear attclear

clean:
	-$(RM) $(TARGET)
	-$(RM) $(LOGS)

# $(OUTS) $(TOCS) $(AUXS)

clear: attclear
	-$(RM) $(BAKS) # *~
	-$(RM) $(LOGS)
	-$(RM) $(OUTS) $(TOCS)
	-$(RM) $(AUXS)
	-$(RM) $(BLXS)
	-$(RM) $(NAVS)
	-$(RM) $(IDXS)

attclear:
	-$(RM) $(ATTTMP)

distclean: clean clear attclear
	-$(RM) $(ATT)
	-$(RM) $(BALL)

dist: $(TARGET)
	$(MV) $(TARGET) $(TITLE).pdf
	$(TAR) $(BALL) $(SRC) $(DEPS) $(EXTRA) $(TITLE).pdf
	$(CP) $(BALL) $(TITLE)-`date -u -d now +%Y-%m-%d-%H-%M`.tar.bz2
	$(MV) $(TITLE).pdf $(TARGET)

exec: $(TARGET)
	$(OPEN) $(TARGET)

